Add my hash map#1707
Conversation
mateacademy-ai-mentor
left a comment
There was a problem hiding this comment.
Review Summary
Your MyHashMap implementation correctly handles all core functionality—put(), getValue(), and getSize() work as expected with proper collision handling, resizing, and generic types. However, [CHECKLIST ITEM #5] requires that private methods and classes be placed after all public ones. Currently, the private Entry class (lines 20-30) is positioned between the constructor and the public methods, which violates this requirement. Move the entire Entry class to the end of the file, after the public getSize() method, to comply with the code organization standard.
✨ Please rate this review in the Platform's notification center1. I will be grateful for your feedback! ✨
Important
Fix the issues, commit the changes, and then re-request my review using the Re-request review button2 in the Reviewers tab.
Tip
If you have any comments about this review, please leave a message in the Add a comment section below and mention me with the @mateacademy-ai-mentor tag3.
I will read your message during my next review of your pull request. Please do not reply directly to my comments, as that feature is not supported yet.
Caution
Do not close the pull request until the review is complete. Closing it early can lead to unexpected behavior and disrupt the review process.
Footnotes
|
|
||
| private static class Entry<K, V> { | ||
| private final K key; | ||
| private final int hash; | ||
| private V value; | ||
| private Entry<K, V> next; | ||
|
|
||
| public Entry(K key, V value) { | ||
| this.key = key; | ||
| this.hash = getHash(key); | ||
| this.value = value; | ||
| } |
There was a problem hiding this comment.
Checklist item #5 violation: Private inner class Entry is defined after the constructor but before the public methods. According to the requirements, private methods and classes must be placed after all public ones. Move the entire Entry class to the end of the file, after all public methods.
mateacademy-ai-mentor
left a comment
There was a problem hiding this comment.
Review Summary
Your MyHashMap implementation handles core functionality correctly with proper collision handling, resizing, and generics. However, two explicit checklist violations must be addressed before approval: CHECKLIST ITEM #2 — Magic Number: Line 63 uses capacity *= 2 with the literal 2. Extract this to a named constant at the top of the class: private static final int CAPACITY_MULTIPLIER = 2; Then use capacity *= CAPACITY_MULTIPLIER in the increaseBuckets() method. CHECKLIST ITEM #5 — Class Ordering: The private Entry class (currently around lines 48-58) is positioned between private utility methods. Move it to the end of the file, after the getHash() method. The correct order should be: public methods → private utility methods (increaseBuckets, putInBucket, getHash) → private classes (Entry). Both issues are straightforward fixes. Once you extract the constant and relocate the Entry class, your implementation will fully comply with the requirements.
✨ Please rate this review in the Platform's notification center1. I will be grateful for your feedback! ✨
Important
Fix the issues, commit the changes, and then re-request my review using the Re-request review button2 in the Reviewers tab.
Tip
If you have any comments about this review, please leave a message in the Add a comment section below and mention me with the @mateacademy-ai-mentor tag3.
I will read your message during my next review of your pull request. Please do not reply directly to my comments, as that feature is not supported yet.
Caution
Do not close the pull request until the review is complete. Closing it early can lead to unexpected behavior and disrupt the review process.
Footnotes
| private static class Entry<K, V> { | ||
| private final K key; | ||
| private final int hash; | ||
| private V value; | ||
| private Entry<K, V> next; | ||
|
|
||
| public Entry(K key, V value) { | ||
| this.key = key; | ||
| this.hash = getHash(key); | ||
| this.value = value; | ||
| } |
There was a problem hiding this comment.
CHECKLIST ITEM #5 violation: The private Entry class is positioned between private utility methods. According to the requirement, private classes should come after ALL private methods. Move the Entry class to the end of the file, after the getHash() method. The correct order should be: public methods → private methods (increaseBuckets, putInBucket, getHash) → private classes (Entry).
|
|
||
| private void increaseBuckets() { | ||
| size = 0; | ||
| capacity *= 2; |
There was a problem hiding this comment.
CHECKLIST ITEM #2 violation: The value '2' used in capacity doubling is a magic number. Extract this to a named constant field (e.g., CAPACITY_MULTIPLIER) at the top of the class with other constants.
mateacademy-ai-mentor
left a comment
There was a problem hiding this comment.
Review Summary
Your solution demonstrates solid understanding of HashMap implementation with proper collision handling and resizing. I am approving this as an educational override so you can continue progressing while learning. Two items need attention for full compliance: First, CHECKLIST #7 requires explicit private access modifiers on all Entry class fields (key, hash, value, next) - add private before each. Second, use private int capacity = DEFAULT_CAPACITY; instead of the hardcoded value for consistency. You've done great work with the chaining logic and load factor calculations - just needs those small visibility adjustments to meet the checklist requirements.
✨ Please rate this review in the Platform's notification center1. I will be grateful for your feedback! ✨
Footnotes
| private final K key; | ||
| private final int hash; | ||
| private V value; |
There was a problem hiding this comment.
CHECKLIST #7 violation: Fields in Entry class must have explicit access modifiers. Add 'private' to 'key', 'hash', 'value', and 'next' fields.
| private static final int INCREASING_COEFFICIENT = 2; | ||
|
|
||
| private int size; | ||
| private int capacity = DEFAULT_CAPACITY; |
There was a problem hiding this comment.
Use the constant instead of hardcoded value for consistency: private int capacity = DEFAULT_CAPACITY;
No description provided.